package ejemplo;
/* Se añade esta linea usando Netbeans */
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Login extends HttpServlet {

  private String mensaje;
   
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {} 

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {} 

  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {
    RequestDispatcher rd;
    String login=request.getParameter("login");
    String pwd=request.getParameter("password");
    //if login and password match
    if(login.equals("root") && pwd.equals("12345"))
        rd=request.getRequestDispatcher("/menu");
    else{
        rd=request.getRequestDispatcher("/index");       
        mensaje="Error: Usuario y/o Password no validos";
        request.setAttribute("mensaje",mensaje);
    }
    rd.forward(request,response);
  }

  @Override
  public String getServletInfo(){ return "Short description"; }
}